package com.nervenets.web.controller.handler.admin.setting;

import com.nervenets.web.controller.handler.SessionHandler;
import com.nervenets.web.controller.handler.common.IdTokenParams;
import com.nervenets.web.entity.MessageCode;
import com.nervenets.web.enumeration.Role;
import com.nervenets.web.hibernate.domain.setting.Help;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

public class HelpDeleteHandler extends SessionHandler<IdTokenParams> {
    @Override
    public ArrayList<Role> allowRoles() {
        return Role.administrator();
    }

    @Override
    public boolean needLog() {
        return false;
    }

    @Override
    public String handle(IdTokenParams params, HttpServletRequest request) throws Exception {
        Help help = userDao.findById(params.getTargetId(), Help.class);
        if (null == help) return errorMessage(MessageCode.code_444, "您要删除的帮助文档不存在！");
        userDao.delete(help);

        return successMessage();
    }

    @Override
    public String result() throws Exception {
        return null;
    }
}
